﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Windows;
using System.Windows.Interactivity;

namespace TheOliver.Controls
{
    public class FadeInOutAnimation : TargetedTriggerAction<FrameworkElement>
    {
        // properties
        public TimeSpan Time { get; set; } // how long must the animation take
        public enum Fade { FadeIn, FadeOut };
        public Fade FadeOptions { get; set; } // kind of animation

        // invoke method wil execute the behaviour
        protected override void Invoke(object parameter)
        {
            // get the element that must be animated
            FrameworkElement myElement = this.AssociatedObject as FrameworkElement;

            // check if we need to fade in or fade out
            double value;
            if (FadeOptions == Fade.FadeIn) value = 1; else value = 0;

            // start the animation
            Animation.playAnimation(myElement.Name, "Opacity", this.Time, value);
        }
    }
}
